//
//  FBOrderViewStatus_OrderWaitingFangBi_AliPayOrWechat.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/10.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "FBOrderViewStatus_OrderWaitingFangBi_AliPayOrWechat.h"
#import "PayTypeSelectedButton.h"


@interface FBOrderViewStatus_OrderWaitingFangBi_AliPayOrWechat ()
@property (nonatomic,strong)UILabel * lab1;
@property (nonatomic,strong)UILabel * lab2;
@property (nonatomic,strong)UILabel * lab3;
@property (nonatomic,strong)UILabel * lab4;
@property (nonatomic,strong)UILabel * lab5;
@property (nonatomic,strong)UILabel * lab6;


@property (nonatomic,strong)UILabel * lab7;
@property (nonatomic,strong)UILabel * lab8;
@property (nonatomic,strong)UILabel * lab9;
@property (nonatomic,strong)UILabel * lab10;
@property (nonatomic,strong)UILabel * lab11;
@property (nonatomic,strong)UILabel * lab12;

@property (nonatomic,strong)UIView * line;
@property (nonatomic,strong)PayTypeSelectedButton  * selectedBtn;

@property (nonatomic,strong) UILabel * unReadOrderLab;


@end

@implementation FBOrderViewStatus_OrderWaitingFangBi_AliPayOrWechat

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[UIColor whiteColor];
        [self createUI];
    }
    return self;
}


-(void)createUI{
    
    //11.000
    UILabel * lab1 = [[UILabel alloc]init];
    [self addSubview:lab1];
    [self setLab:lab1 withColor:RGB(30, 63, 89) andFont:24 andText:@"加载中..." andTextAlignment:NSTextAlignmentCenter];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(20);
        make.left.equalTo(self.mas_left);
        make.height.equalTo(@(30));
        make.width.equalTo(@(G_SCREENWIDTH));
    }];
    _lab1=lab1;
    //壹拾壹元整
    UILabel * lab2 = [[UILabel alloc]init];
    [self addSubview:lab2];
    [self setLab:lab2 withColor:RGB(30, 63, 89) andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentCenter];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab1.mas_bottom).offset(0);
        make.left.equalTo(self.mas_left);
        make.height.equalTo(@(30));
        make.width.equalTo(@(G_SCREENWIDTH));
    }];
    _lab2=lab2;
    UIImageView * timeimgV=[[UIImageView alloc]init];
    [self addSubview:timeimgV];
    timeimgV.image=[UIImage imageNamed:@"时间icon"];
    [timeimgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset((G_SCREENWIDTH-150)/2.0);
        make.top.equalTo(lab2.mas_bottom).offset(10);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(15);
    }];
    
    UILabel * lab3 = [[UILabel alloc]init];
    [self addSubview:lab3];
    [self setLab:lab3 withColor:[UIColor redColor] andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentLeft];
    [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(timeimgV.mas_centerY).offset(0);
        make.left.equalTo(timeimgV.mas_right).offset(10);
        make.height.equalTo(@(30));
        //        make.width.equalTo(@(G_SCREENWIDTH));
    }];
    _lab3=lab3;
    UILabel * time = [[UILabel alloc]init];
    [self addSubview:time];
    [self setLab:time withColor:RGB(30, 63, 89) andFont:12 andText:@"加载中" andTextAlignment:NSTextAlignmentLeft];
    [time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(timeimgV.mas_centerY).offset(0);
        make.left.equalTo(lab3.mas_right).offset(10);
        make.height.mas_equalTo(30);
        //        make.width.mas_equalTo(100);
    }];
    
    _time=time;
    
    PayTypeSelectedButton  * selectedBtn = [[PayTypeSelectedButton alloc]init];
    [self addSubview:selectedBtn];
    _selectedBtn=selectedBtn;
    selectedBtn.logo.image=[UIImage imageNamed:@"微信-3"];
    selectedBtn.lab.text = @"微信";
    selectedBtn.imgVselected.hidden=YES;
    [selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(30));
        make.left.equalTo(self.mas_left).offset(0);
        make.right.equalTo(self.mas_right).offset(0);
        make.top.equalTo(timeimgV.mas_bottom).offset(15);
    }];
    
    UILabel * lab4 = [[UILabel alloc]init];
    UILabel * lab5 = [[UILabel alloc]init];
    _lab4=lab4;
    _lab5=lab5;
    [self setLeftText:@"收款人" andLab:lab4 andIndex:0];
    [self setLeftText:@"收款账号" andLab:lab5 andIndex:1];
    
    
    UILabel * lab6 = [[UILabel alloc]init];
    [self addSubview:lab6];
    [self setLab:lab6 withColor:RGB(140, 159, 173) andFont:12 andText:@"收款码" andTextAlignment:NSTextAlignmentLeft];
    [lab6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(30));
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-150);
        make.top.equalTo(lab5.mas_bottom).offset(3);
    }];
    _lab6=lab6;
    UIButton *  btn1 = [[UIButton alloc]init];
    [self addSubview:btn1];
    btn1.imageView.size=CGSizeMake(22, 21) ;
    [btn1 setTitleColor:ThemeColor forState:UIControlStateNormal];
    btn1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [btn1 addTarget:self action:@selector(openQRcode) forControlEvents:UIControlEventTouchUpInside];
    btn1.backgroundColor=MC_TEST_COLOR;
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(30));
        make.width.mas_equalTo(80);
        make.right.equalTo(lab5.mas_right).offset(0);
        make.top.equalTo(lab5.mas_bottom).offset(3);
    }];
    
    UIImageView * imgV = [[UIImageView alloc]init];
    [btn1 addSubview:imgV];
    imgV.image = [UIImage imageNamed:@"二维码icon"];
    [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(btn1.mas_centerY).offset(0);
        make.right.equalTo(btn1.mas_right).offset(0);
        make.width.mas_equalTo(22);
        make.height.mas_equalTo(21);
    }];
    
    UIView * line = [[UIView alloc]init];
    [self addSubview:line];
    line.backgroundColor=RGB(232, 234, 237);
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(btn1.mas_bottom).offset(10);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(G_SCREENWIDTH-30);
        make.height.mas_equalTo(1);
    }];
    _line=line;
    
    [self setLeftText:@"对方" andRtext:@"" andIndex:0 andbg:self];
    [self setLeftText:@"订单金额" andRtext:@"" andIndex:1 andbg:self];
    [self setLeftText:@"单价" andRtext:@"" andIndex:2 andbg:self];
    [self setLeftText:@"数量" andRtext:@"" andIndex:3 andbg:self];
    [self setLeftText:@"订单号" andRtext:@"" andIndex:4 andbg:self];
    [self setLeftText:@"订单时间" andRtext:@"" andIndex:5 andbg:self];
    
    
    UIButton *  chat = [[UIButton alloc]init];
    [self addSubview:chat];
    [chat setTitleColor:ThemeColor forState:UIControlStateNormal];
    [chat setImage:[UIImage imageNamed:@"消息icon"] forState:UIControlStateNormal];
    chat.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    chat.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [chat addTarget:self action:@selector(GoToChatVC) forControlEvents:UIControlEventTouchUpInside];
    chat.backgroundColor=RGB(255, 255, 255);
    [chat.imageView setContentMode:UIViewContentModeScaleAspectFill];
    [chat mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(49-kTabBarHeight);
        make.left.equalTo(self.mas_left).offset(0);
        make.width.mas_equalTo(65);
        make.height.mas_equalTo(49);
    }];
    
    
    
    UILabel * unReadOrderLab = [[UILabel alloc]init];
    [self addSubview:unReadOrderLab];
    unReadOrderLab.layer.borderColor = [UIColor whiteColor].CGColor;
    unReadOrderLab.layer.borderWidth = 1;
    [self setLab:unReadOrderLab withColor:[UIColor whiteColor] andFont:9 andText:@"" andTextAlignment:NSTextAlignmentCenter];
    unReadOrderLab.layer.cornerRadius = 9;
    unReadOrderLab.clipsToBounds=YES;
    unReadOrderLab.backgroundColor=[UIColor redColor];
    [unReadOrderLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.mas_bottom).offset(49-kTabBarHeight+9);
        make.left.equalTo(self.mas_left).offset(65/2.0+3);
        make.width.mas_equalTo(18);
        make.height.mas_equalTo(18);
    }];
    _unReadOrderLab=unReadOrderLab;
    _unReadOrderLab.hidden=YES;
    
    UIButton *  btn2 = [[UIButton alloc]init];
    [self addSubview:btn2];
    [btn2 setTitleColor:RGB(99, 140, 220) forState:UIControlStateNormal];
    [btn2 setTitle:@"申诉" forState:UIControlStateNormal];
    btn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    btn2.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [btn2 addTarget:self action:@selector(shenSu) forControlEvents:UIControlEventTouchUpInside];
    btn2.backgroundColor=RGB(235, 240, 248);
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(49-kTabBarHeight);
        make.left.equalTo(self.mas_left).offset(65);
        make.width.mas_equalTo((G_SCREENWIDTH-65)/2.0);
        make.height.mas_equalTo(49);
    }];
    
    UIButton *  btn3 = [[UIButton alloc]init];
    [self addSubview:btn3];
    [btn3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn3 setTitle:@"对方正在放币" forState:UIControlStateNormal];
    btn3.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    btn3.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    btn3.backgroundColor=RGB(99, 140, 220);
    [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(49-kTabBarHeight);
        make.right.equalTo(self.mas_right).offset(0);
        make.width.mas_equalTo((G_SCREENWIDTH-65)/2.0);
        make.height.mas_equalTo(49);
    }];

    
    
}

-(void)setDataSource:(FBFindorderModel *)dataSource{
    _dataSource = dataSource;
    
    _lab1.text = [NSString stringWithFormat:@"%@",dataSource.amount];
    _lab2.text = [NSString stringWithFormat:@"%@",dataSource.amount];
    _lab3.text = [FBFindorderTool GetStatusName:dataSource.status andPayType:dataSource.order_type];
    
    if (_payType == FBPayType_Wechat) {
        NSDictionary * WechatPay = dataSource.WechatPay;
        NSDictionary * account = WechatPay[@"account"];
        _lab4.text = [NSString stringWithFormat:@"%@",account[@"name"]];
        _lab5.text = [NSString stringWithFormat:@"%@",account[@"account"]];
    }else if(_payType == FBPayType_ALiPay){
        NSDictionary * ALiPay = dataSource.ALiPay;
        NSDictionary * account = ALiPay[@"account"];
        _lab4.text = [NSString stringWithFormat:@"%@",account[@"name"]];
        _lab5.text = [NSString stringWithFormat:@"%@",account[@"account"]];
    }
    
    _lab7.text = [NSString stringWithFormat:@"%@",self.dataSource.bill_nickname];
    _lab8.text = [NSString stringWithFormat:@"%@ %@",self.dataSource.amount,self.dataSource.legal];
    _lab9.text = [NSString stringWithFormat:@"%@ %@/%@",self.dataSource.price,self.dataSource.legal,self.dataSource.symbol];
    _lab10.text = [NSString stringWithFormat:@"%@ %@",self.dataSource.volume,self.dataSource.symbol];
    _lab11.text = [NSString stringWithFormat:@"%@",self.dataSource.order_sn];
    _lab12.text = [NSString stringWithFormat:@"%@",self.dataSource.create_time];
    
}


-(void)setLeftText:(NSString *)text1 andRtext:(NSString *)text2 andIndex:(NSInteger)index  andbg:(UIView * )bbg{
    CGFloat Top = index* 33 +5;
    UILabel * left = [[UILabel alloc]init];
    [self addSubview:left];
    [self setLab:left withColor:RGB(140, 159, 173) andFont:14 andText:text1 andTextAlignment:NSTextAlignmentLeft];
    [left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line.mas_top).offset(Top);
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.height.equalTo(@(30));
    }];
    
    text2 = [NSString stringWithFormat:@"%@",text2];
    UILabel * right = [[UILabel alloc]init];
    [self addSubview:right];
    [self setLab:right withColor:RGB(30, 63, 89) andFont:14 andText:text2 andTextAlignment:NSTextAlignmentRight];
    [right mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line.mas_top).offset(Top);
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.height.equalTo(@(30));
    }];
    if (index==0) {
        _lab7 = right;
    }else if (index==1){
        _lab8 = right;
    }else if (index==2){
        _lab9 = right;
    }else if (index==3){
        _lab10 = right;
    }else if (index==4){
        _lab11 = right;
    }else if (index==5){
        _lab12 = right;
    }
    
}


-(void)setLeftText:(NSString *)text1 andLab:(UILabel *)lab andIndex:(NSInteger)index {
    CGFloat Top = index* 33 + 10;
    UILabel * left = [[UILabel alloc]init];
    [self addSubview:left];
    [self setLab:left withColor:RGB(140, 159, 173) andFont:13 andText:text1 andTextAlignment:NSTextAlignmentLeft];
    [left mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.selectedBtn.mas_bottom).offset(Top);
        make.left.equalTo(self.mas_left).offset(15);
        make.right.equalTo(self.mas_right).offset(-15);
        make.height.equalTo(@(30));
    }];
    
    
    [self addSubview:lab];
    [self setLab:lab withColor:RGB(30, 63, 89) andFont:13 andText:@"加载中" andTextAlignment:NSTextAlignmentRight];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.selectedBtn.mas_bottom).offset(Top);
        make.width.mas_equalTo(G_SCREENWIDTH-30);
        make.left.equalTo(self.mas_left).offset(15);
        make.height.equalTo(@(30));
    }];
}


-(void)setLab:(UILabel *)lab withColor:(UIColor *)color andFont:(CGFloat)font andText:(NSString *)text andTextAlignment:(NSTextAlignment)textAlignment{
    lab.text=text;
    lab.textColor=color;
    lab.font=[UIFont systemFontOfSize:font];
    lab.textAlignment=textAlignment;
}


-(void)openQRcode{
    if (self.block) {
        self.block(FBFindorderActionType_LookQRcode);
    }
}



-(void)shenSu{
    if (self.block) {
        self.block(FBFindorderActionType_ShenSu);
    }
}

-(void)GoToChatVC{
    if (self.block) {
        self.block(FBFindorderActionType_GoToChat);
    }
}
#pragma mark-设置未读消息数量
-(void)setUnReadOrderNum{
    
    FBFindorderUnReadOrder * FU = [FBFindorderUnReadOrder sharedFBFindorderUnReadOrder];
    NSLog(@"%@",self.dataSource.order_sn);
    NSString * order_sn = [NSString stringWithFormat:@"%@",self.dataSource.order_sn];
    NSString * Num = [NSString stringWithFormat:@"%@",FU.UnReadOrderDic[order_sn]];
    if ([Num integerValue]>0) {
        _unReadOrderLab.text=Num;
        _unReadOrderLab.hidden=NO;
        if ([Num integerValue]<10) {
            _unReadOrderLab.font = [UIFont boldSystemFontOfSize:9];
        }
    }else{
        _unReadOrderLab.hidden=YES;
    }
    
}
@end





